package org.chen.newsapi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.chen.newsapi.dto.CategoryVO;
import org.chen.newsapi.entity.Category;

import java.util.List;

@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
    
    @Select("SELECT c.id, c.name, c.display_name, c.description, c.icon_url, c.sort_order, " +
            "COUNT(a.id) as article_count " +
            "FROM categories c " +
            "LEFT JOIN articles a ON c.name = a.category AND a.status = 1 " +
            "WHERE c.is_active = 1 " +
            "GROUP BY c.id, c.name, c.display_name, c.description, c.icon_url, c.sort_order " +
            "ORDER BY c.sort_order ASC")
    List<CategoryVO> selectCategoriesWithCount();
}